<template>
  <div class="app-cont">
    <alertTip v-if="showAlert" @closeTip="go()" :alertText="alertText"></alertTip>

    <!--这是 Header 区域 -->
    <!--<div class="header">-->
      <!--<headers title="修改手机"></headers>-->
    <!--</div>-->
    <div class="main">
      <div class="main-container">
        <div class="fenlei">
          <div class="xiugai">
            <p>我们已经发送了校验码到你的手机:</p>
            <p>{{phone | getNum}}</p>
            <mt-field label="校验码" placeholder="请输入短信校验码" type="text" v-model="isMobileCode">
              <div class="mint-field-other" v-on:click="Againsend" v-show="show">重新发送</div>
              <div class="mint-field-other" v-show="!show">{{count}}秒后重新发送</div>
            </mt-field>
            <a href="javascript:;" class="btn-next" @click="ModifyPhoneNext">下一步</a>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
  import wx from 'weixin-js-sdk'
  import { wxHttpTool,wx_config, http_getParam, get_shopQrcoe,wx_share,wx_hideAllMenu } from '../components/httpUtil/httpUtil'
  import {msg_10046} from '../message/msg_10046'
  import {relogin} from "../components/httpUtil/httpUtil";

  export default {
    name: 'ModifyPhoneNext',
    data () {
      return {
        phone: this.phone,
        isMobileCode: '',
        show: true,
        count: '',
        showAlert:false,
        alertText:null
      }
    },
    created () {
      wxHttpTool.wxAuthor(this, function (varRet, varJson, varThis = this) {
        if (varRet == -1) {
          varThis.alertTip('网络错误');
          varThis.go = function () {
            varThis.showAlert = false;
          }

        }
        // 关注钱应该判断下是否已经关注过了
        msg_10046.send(varThis,msg_10046.entity(),function(varThis,res){
          varThis.wxlist=res.data.p.sign
          wx_config(varThis.wxlist);
          wx_hideAllMenu();
          wx.hideMenuItems({
            //禁用单独分享朋友圈QQ空间等功能
            menuList: ["menuItem:share:timeline","menuItem:share:QZone","menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
          });
        })


      },this.type)
      this.phone = localStorage.getItem('phone');
      this.Againsend()
    },
    mounted: function () {
    },
    methods: {
      alertTip(msg){
        this.showAlert = true;
        this.alertText = msg;
      },
      go(){
         this.showAlert = false;
      },
      //  重新获取验证码
      Againsend: function () {
        // 点击按钮 提交接口信息
        let number = localStorage.getItem("phone")
        const jsonValue = JSON.stringify({
          "c": "10003",
          "p": {
            "mobile": number,
          }
        })
        this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
          console.log(res);
          const data = res.data.p;
          if (data.isTrue === true) {
            //          this.$emit('has-log', res.data.username);
          } else {
            this.alertTip(data.errorMsg);
            if (data.errorCode === 90) {
              this.go = ()=> {
                this.showAlert = false
                let _this = this;
                relogin(_this)
              }
            }
          }
        })
        .catch((error) => {
          console.log(error);
        });

        //倒计时   60s计时器
        const TIME_COUNT = 60;
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.show = false;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000)
        }
      },
      //  验证验证码
      ModifyPhoneNext () {
        const jsonValue = JSON.stringify({
          "c": "10002",
          "p": {
            "mobileCode": this.isMobileCode, //手机验证码
          }
        });
        //   判断验证码是否正确
        this.$http.post(api + '/qqs.us', jsonValue)
          .then((response) => {
            if (response.data.p.isTrue === true) {
              this.alertTip("修改成功");
              this.go = function(){
                 this.showAlert = false;
              }
              // alert()
              console.log(response)
//                this.$router.push({name: 'Invitation'})
            } else {
              localStorage.removeItem('phone')
              this.alertTip(response.data.p.errorMsg);
              if (response.data.p.errorCode === 90) {
                this.go = ()=> {
                  this.showAlert = false
                  let _this = this;
                  relogin(_this)
                }
              }

            }
          })
          .catch((error) => {
            console.log(error);
          })
      },
    },
    filters: {
      getNum (value) {
        console.log(1)
        let reg = /^(\d{3})\d+(\d{4})$/ // 正则不匹配空格
        return value.replace(reg, '$1 **** $2')
      }
    }
  }
</script>

<style lang="scss" scoped>
  .app-cont {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    /*padding: 80px 0 0;*/
    box-sizing: border-box;
    .header {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 80px;
    }
    .main {
      flex: 1;
      position: relative;
      .main-container {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
      }
    }
  }

  .fenlei {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overflow-y: auto;
    background-color: #f4f4f4;
    display: flex;
    flex-direction: column;
    ::-webkit-scrollbar {
      display: none;
    }

  }

</style>
<style lang="scss">
  a:hover, a:visited, a:link, a:active {
    text-decoration: none;
    outline: none;
  }

  .xiugai {
    height: 100%;
    > p:nth-child(1) {
      height: 80px;
      box-sizing: border-box;
      padding: 30px 0 26px 0;
      user-select: none;
      font-size: 24px;
      color: #3b3b43;
      text-align: center;
    }
    > p:nth-child(2) {
      font-size: 30px;
      text-align: center;
      padding-top: 22px;
      padding-bottom: 48px;
    }
    .mint-cell {
      height: 94px;
      box-sizing: border-box;
      padding-left: 20px;
      padding-right: 20px;
    }
    .mint-cell-title {
      width: 94px;
    }
    .mint-field-other {
      font-size: 22px;
      color: #a1a1a1;
    }
    .mint-field-core {
      text-align: center;
      box-sizing: border-box;
      padding-right: 18px;
    }
    .btn-next {
      position: fixed;
      bottom: 20px;
      left: 50%;
      transform: translate(-50%);
      background-color: #fff;
      display: block;
      margin: 0 auto 0;
      width: 580px;
      height: 74px;
      border-radius: 35px;
      border: 1px solid #fe3519;
      color: #fe3519;
      text-align: center;
      line-height: 74px;
      font-size: 26px;
    }
  }

</style>
